// pages/inkEventSign3/inkEventSign3.js
import profile from '../../profile.js'

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    lang: app.globalData.language,
    index: profile.inkSign,

    createDate: '',

    // 上传作品列表
    inkProductList: [{
      id: 1,
      img: '../../images/upload_img_demo.jpg'
    },{
      id: 2,
      img: '../../images/upload_img_demo1.jpg'
    },{
      id: 3,
      img: '../../images/upload_img_demo.jpg'
    }],
    productNum: 3,

    rulesChecked: true,
    popShow: false,
    rulesChecked1: true,
    popShow1: false,
    popShow2: false,
  },

  // 弹层事件
  popBtnTap: function (e) {
    this.setData({
      popShow: false,
      popShow1: false,
      popShow2: false,
      rulesChecked: true,
      rulesChecked1: true
    })
  },

  rulesTap2: function (e) {
    this.setData({
      popShow2: true,
    })
  },

  rulesTap1: function (e) {
    this.setData({
      popShow1: true,
    })
  },

  rulesTap: function (e) {
    this.setData({
      popShow: true,
    })
  },

  // 删除作品
  deleteUpTap: function (e) {
    let list = this.data.inkProductList, id = e.currentTarget.id, num = list.length;
    //console.log(id);
    for (let i=0;i<list.length;i++) {
      if (id == list[i].id) {
        list.splice(i,1);
        num --;
      }
    }
    this.setData({
      inkProductList: list,
      productNum: num
    })
  },

  // 上传作品图片按钮
  bindUploadImgTap: function (e) {
    let id = Math.random(), that = this, list = this.data.inkProductList, object = {}, num = list.length;
    if (num == 3) return;
    wx.chooseMedia({
      mediaType: 'image',
      sourceType: 'album',
      success(res) {
        //console.log(res.tempFiles[0].tempFilePath);
        object.id = id;
        object.img = res.tempFiles[0].tempFilePath;
        list.push(object)
        num ++;
        that.setData({
          inkProductList: list,
          productNum: num
        })
      }
    })
  },

  bindPickerChangeDate1: function (e) {
    this.setData({
      createDate: e.detail.value
    })
  },

  // 语言切换事件
  menuTap: function (e) {
    this.setData({
      lang: e.detail.lang
    })
    if (app.globalData.language == 'cn'){
      wx.setNavigationBarTitle({
        title: '大华银行艺术探索'
      })
    }else{
      wx.setNavigationBarTitle({
        title: 'UOB Art Explorer'
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})